<template>
    <el-divider/>
    <el-icon>
        <DocumentChecked/>
    </el-icon>
    <span>
 在诊患者
    </span>
    <el-divider/>
    <div class="patientSearch">
        <div>
            <el-input v-model="searchInfo.caseNumber" placeholder="请输入患者病历号"/>
        </div>
        <div>
            <el-input v-model="searchInfo.realName" placeholder="请输入患者姓名"/>
        </div>
        <el-button type="primary" style="margin-left: 1vw" @click="queryPatientByCondition()">搜索</el-button>
    </div>
    <el-divider/>
    <el-table :data="patientInfoList" stripe table-layout="auto">
        <el-table-column label="患者病历号">
            <template #default="scope">
                <div style="display: flex; align-items: center">
                    <span style="margin-left: 10px">{{ scope.row.caseNumber }}</span>
                </div>
            </template>
        </el-table-column>
        <el-table-column label="患者姓名">
            <template #default="scope">
                <div style="display: flex; align-items: center">
                    <span style="margin-left: 10px">{{ scope.row.realName }}</span>
                </div>
            </template>
        </el-table-column>
        <el-table-column label="患者身份证">
            <template #default="scope">
                <div style="display: flex; align-items: center">
                    <span style="margin-left: 10px">{{ scope.row.cardNumber }}</span>
                </div>
            </template>
        </el-table-column>
        <el-table-column label="患者状态">
            <template #default="scope">
                <div style="display: flex; align-items: center">
                    <span style="margin-left: 10px" v-if="scope.row.visitState==2">医生接诊</span>
                </div>
            </template>
        </el-table-column>
        <el-table-column label="挂号时间">
            <template #default="scope">
                <div style="display: flex; align-items: center">
                    <span style="margin-left: 10px">{{ scope.row.visitDate }}</span>
                </div>
            </template>
        </el-table-column>
        <el-table-column label="操作">
            <template #default="scope">
                <el-button size="small" @click="updatePatientInfo(scope.row)">更新病历</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-divider/>
</template>

<script setup>
import {provide, ref, computed} from "vue";
import {DocumentChecked} from '@element-plus/icons-vue'
import axios from "axios";
import router from "../../router/index.js";

axios.defaults.baseURL = "http://localhost:8092/"
provide("axios", axios)
const background = ref(false)

const loginEmp = ref({
    id: '1',
    realname: '扁鹊',
})
//根据当前医生查找患者信息列表
const patientInfoList = ref([])
const searchInfo = ref({
    caseNumber: '',
    realName: '',
    employeeId: ''
})
//查询当前医生全部患者列表
axios({
    method: 'get',
    url: 'register/queryRegisterByStateAndDoc/' + '2/' + loginEmp.value.id
}).then(resp => {
    patientInfoList.value = resp.data.data
    console.log(patientInfoList.value)
})

function queryPatientByCondition() {
    searchInfo.value.employeeId = loginEmp.value.id
    if (searchInfo.value.realName == '' && searchInfo.value.realName == '') {
        axios({
            method: 'get',
            url: 'register/queryRegisterByStateAndDoc/' + '2/' + loginEmp.value.id
        }).then(resp => {
            patientInfoList.value = resp.data.data
            console.log(patientInfoList.value)
        })
        return
    }
    axios({
        method: 'post',
        url: 'register/queryPatientByNameOrCaseNum',
        data: searchInfo.value
    }).then(resp => {
        patientInfoList.value = []
        patientInfoList.value[0] = resp.data.data
        console.log(resp.data.data)
    })
}

function updatePatientInfo(val) {
    console.log(val)
    router.push({
        path: '/check_results',
        query: {
           caseNumber:val.caseNumber
        }
    })
}
</script>

<style scoped>
.demo-pagination-block + .demo-pagination-block {
    margin-top: 10px;
}

.demo-pagination-block .demonstration {
    margin-bottom: 16px;
}

.patientSearch {
    display: flex;
}

.patientSearch div {
    margin: 0 1vw 0 1vw;
}

.demo-pagination-block {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.patientNum {
    display: flex;
}

.patientNum div {
    margin: 0 1vw;
}
</style>